package com.jvyou.house.controller;

import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.controller.BaseController;
import com.jvyou.common.core.domain.AjaxResult;
import com.jvyou.common.core.page.TableDataInfo;
import com.jvyou.common.enums.BusinessType;
import com.jvyou.common.utils.poi.ExcelUtil;
import com.jvyou.house.domain.HouseComment;
import com.jvyou.house.service.IHouseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋评论Controller
 *
 * @author Jvyou
 * @date 2024-09-17
 */
@RestController
@RequestMapping("/house/comment")
public class HouseCommentController extends BaseController {
    @Autowired
    private IHouseCommentService houseCommentService;

    /**
     * 查询房屋评论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseComment houseComment) {
        startPage();
        List<HouseComment> list = houseCommentService.selectHouseCommentList(houseComment);
        return getDataTable(list);
    }

    /**
     * 导出房屋评论列表
     */
    @PreAuthorize("@ss.hasPermi('house:comment:export')")
    @Log(title = "房屋评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseComment houseComment) {
        List<HouseComment> list = houseCommentService.selectHouseCommentList(houseComment);
        ExcelUtil<HouseComment> util = new ExcelUtil<HouseComment>(HouseComment.class);
        util.exportExcel(response, list, "房屋评论数据");
    }

    /**
     * 获取房屋评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(houseCommentService.selectHouseCommentById(id));
    }

    /**
     * 新增房屋评论
     */

    @Log(title = "房屋评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseComment houseComment) {
        return toAjax(houseCommentService.insertHouseComment(houseComment));
    }

    /**
     * 修改房屋评论
     */
    @PreAuthorize("@ss.hasPermi('house:comment:edit')")
    @Log(title = "房屋评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseComment houseComment) {
        return toAjax(houseCommentService.updateHouseComment(houseComment));
    }

    /**
     * 删除房屋评论
     */

    @Log(title = "房屋评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(houseCommentService.deleteHouseCommentByIds(ids));
    }
}
